<template>
  <el-image
    style="width: 100px; height: 100px"
    :src="url"
    :preview-src-list="[url]"
  >
  </el-image>
</template>

<script>
import API from "@/api";
export default {
  props: {
    apiKey: String,
    aId: Number,
  },
  data: () => ({
    url: "",
  }),
  created() {
    API[this.apiKey](this.aId)
      .then(({ data: blob }) => {
        // blob 转 base64
        // let oFileReader = new FileReader();
        // oFileReader.onloadend = function (e) {
        //   let base64 = e.target.result;
        // };
        // oFileReader.readAsDataURL(blob);
        //==== blob转url ====
        var img = document.createElement("img");
        img.onload = function (e) {
          window.URL.revokeObjectURL(img.src); // 清除释放
        };
        this.url = window.URL.createObjectURL(blob);
        
      })
      .catch((err) => {});
  },
};
</script>

<style></style>
